package com.fuyin.service;

import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.fuyin.commons.exception.ApiException;
import com.fuyin.commons.response.BaseResponse;
import com.fuyin.commons.response.ErrorCode;
import com.fuyin.commons.utils.MyUtils;
import com.fuyin.dao.GpDao;
import com.fuyin.entity.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.*;

/**
 * @author yuanxilan (yuanxilan@keep.com)
 * @Description
 * @date 2021年12月05日 12:10 AM
 * @since
 */
@Service
@Slf4j
public class FileServiceImpl {

    @Autowired
    private GpDao gpDao;

    public static Map<String, Map<String, String>> alias = new HashMap<>();

    static {
        Map<String, String> mainzbMap = new HashMap<>();
        mainzbMap.put("股票代码", "securityCode");
        mainzbMap.put("股票名字", "securityNameAbbr");
        mainzbMap.put("报告时间", "reportDate");
        mainzbMap.put("基本每股收益 (元)", "epsjb");
        mainzbMap.put("扣非每股收益 (元)", "epskcjb");
        mainzbMap.put("稀释每股收益 (元)", "epsxs");
        mainzbMap.put("每股净资产 (元)", "bps");
        mainzbMap.put("每股公积金 (元)", "mgzbgj");
        mainzbMap.put("每股未分配利润 (元)", "mgwfplr");
        mainzbMap.put("每股经营现金流 (元)", "mgjyxjje");
        mainzbMap.put("营业总收入 (元)", "totaloperatereve");
        mainzbMap.put("归属净利润 (元)", "parentnetprofit");
        mainzbMap.put("扣非净利润 (元)", "kcfjcxsyjlr");
        mainzbMap.put("营业总收入同比增长 (%)", "totaloperaterevetz");
        mainzbMap.put("归属净利润同比增长 (%)", "parentnetprofittz");
        mainzbMap.put("扣非净利润同比增长 (%)", "kcfjcxsyjlrtz");
        mainzbMap.put("营业总收入滚动环比增长 (%)", "yyzsrgdhbzc");
        mainzbMap.put("归属净利润滚动环比增长 (%)", "netprofitrphbzc");
        mainzbMap.put("扣非净利润滚动环比增长 (%)", "kfjlrgdhbzc");
        mainzbMap.put("净资产收益率 (加权)(%)", "roejq");
        mainzbMap.put("净资产收益率 (扣非 / 加权)(%)", "roekcjq");
        mainzbMap.put("总资产收益率 (加权)(%)", "zzcjll");
        mainzbMap.put("毛利率 (%)", "xsmll");
        mainzbMap.put("净利率 (%)", "xsjll");
        mainzbMap.put("流动比率", "ld");
        mainzbMap.put("速动比率", "sd");
        mainzbMap.put("现金流量比率", "xjllb");
        mainzbMap.put("资产负债率 (%)", "zcfzl");
        mainzbMap.put("权益乘数", "qycs");
        mainzbMap.put("产权比率", "cqbl");
        mainzbMap.put("总资产周转天数 (天)", "zzczzts");
        mainzbMap.put("存货周转天数 (天)", "chzzts");
        mainzbMap.put("应收账款周转天数 (天)", "yszkzzts");
        mainzbMap.put("总资产周转率 (次)", "toazzl");
        mainzbMap.put("存货周转率 (次)", "chzzl");
        mainzbMap.put("应收账款周转率 (次)", "yszkzzl");
        Map<String, String> profileMap = new HashMap<>();
        profileMap.put("股票代码", "securityCode");
        profileMap.put("股票名字", "securityNameAbbr");
        profileMap.put("报告时间", "reportDate");
        profileMap.put("营业总收入", "totalOperateIncome");
        profileMap.put("营业收入", "operateIncome");
        profileMap.put("营业总成本", "totalOperateCost");
        profileMap.put("营业成本", "operateCost");
        profileMap.put("税金及附加", "operateTaxAdd");
        profileMap.put("销售费用", "saleExpense");
        profileMap.put("管理费用", "manageExpense");
        profileMap.put("研发费用", "researchExpense");
        profileMap.put("财务费用", "financeExpense");
        profileMap.put("其中：利息费用", "feInterestExpense");
        profileMap.put("利息收入", "feInterestIncome");
        profileMap.put("加：投资收益", "investIncome");
        profileMap.put("资产处置收益", "assetDisposalIncome");
        profileMap.put("资产减值损失 (新)", "assetImpairmentIncome");
        profileMap.put("信用减值损失 (新)", "creditImpairmentIncome");
        profileMap.put("其他收益", "otherIncome");
        profileMap.put("营业利润", "operateProfit");
        profileMap.put("加：营业外收入", "nonbusinessIncome");
        profileMap.put("减：营业外支出", "nonbusinessExpense");
        profileMap.put("利润总额", "totalProfit");
        profileMap.put("减：所得税", "incomeTax");
        profileMap.put("净利润", "netprofit");
        profileMap.put("持续经营净利润", "continuedNetprofit");
        profileMap.put("归属于母公司股东的净利润", "parentNetprofit");
        profileMap.put("扣除非经常性损益后的净利润", "deductParentNetprofit");
        profileMap.put("基本每股收益", "basicEps");
        profileMap.put("稀释每股收益", "dilutedEps");
        profileMap.put("综合收益总额", "totalCompreIncome");
        profileMap.put("归属于母公司股东的综合收益总额", "parentTci");
        profileMap.put("审计意见 (境内)", "opinionType");
        Map<String, String> xjllMap = new HashMap<>();
        xjllMap.put("股票代码", "securityCode");
        xjllMap.put("股票名字", "securityNameAbbr");
        xjllMap.put("发布日期", "reportDate");
        xjllMap.put("销售商品、提供劳务收到的现金", "salesServices");
        xjllMap.put("收到的税收返还", "receiveTaxRefund");
        xjllMap.put("收到其他与经营活动有关的现金", "receiveOtherOperate");
        xjllMap.put("经营活动现金流入小计", "totalOperateInflow");
        xjllMap.put("购买商品、接受劳务支付的现金", "buyServices");
        xjllMap.put("支付给职工以及为职工支付的现金", "payStaffCash");
        xjllMap.put("支付的各项税费", "payAllTax");
        xjllMap.put("支付其他与经营活动有关的现金", "payOtherOperate");
        xjllMap.put("经营活动现金流出小计", "totalOperateOutflow");
        xjllMap.put("经营活动产生的现金流量净额", "netcashOperate");
        xjllMap.put("处置固定资产、无形资产和其他长期资产收回的现金净额", "disposalLongAsset");
        xjllMap.put("处置子公司及其他营业单位收到的现金", "disposalSubsidiaryOther");
        xjllMap.put("收到的其他与投资活动有关的现金", "receiveOtherInvest");
        xjllMap.put("投资活动现金流入小计", "totalInvestInflow");
        xjllMap.put("购建固定资产、无形资产和其他长期资产支付的现金", "constructLongAsset");
        xjllMap.put("取得子公司及其他营业单位支付的现金净额", "obtainSubsidiaryOther");
        xjllMap.put("支付其他与投资活动有关的现金", "payOtherInvest");
        xjllMap.put("投资活动现金流出小计", "totalInvestOutflow");
        xjllMap.put("投资活动产生的现金流量净额", "netcashInvest");
        xjllMap.put("分配股利、利润或偿付利息支付的现金", "assignDividendPorfit");
        xjllMap.put("筹资活动现金流出小计", "totalFinanceOutflow");
        xjllMap.put("筹资活动产生的现金流量净额", "netcashFinance");
        xjllMap.put("现金及现金等价物净增加额", "cceAdd");
        xjllMap.put("加：期初现金及现金等价物余额", "beginCce");
        xjllMap.put("期末现金及现金等价物余额", "endCce");
        xjllMap.put("净利润", "netprofit");
        xjllMap.put("资产减值准备", "assetImpairment");
        xjllMap.put("固定资产和投资性房地产折旧", "faIrDepr");
        xjllMap.put("其中：固定资产折旧、油气资产折耗、生产性生物资产折旧", "oilgasBiologyDepr");
        xjllMap.put("无形资产摊销", "iaAmortize");
        xjllMap.put("长期待摊费用摊销", "lpeAmortize");
        xjllMap.put("处置固定资产、无形资产和其他长期资产的损失", "disposalLongassetLoss");
        xjllMap.put("固定资产报废损失", "faScrapLoss");
        xjllMap.put("投资损失", "investLoss");
        xjllMap.put("递延所得税", "deferTax");
        xjllMap.put("其中：递延所得税资产减少", "dtAssetReduce");
        xjllMap.put("存货的减少", "inventoryReduce");
        xjllMap.put("经营性应收项目的减少", "operateReceReduce");
        xjllMap.put("经营性应付项目的增加", "operatePayableAdd");
        xjllMap.put("其他", "other");
        xjllMap.put("经营活动产生的现金流量净额其他项目", "operateNetcashOthernote");
//        xjllMap.put("经营活动产生的现金流量净额", "netcashOperatenote");
        xjllMap.put("现金的期末余额", "endCash");
        xjllMap.put("减：现金的期初余额", "beginCash");
        xjllMap.put("现金及现金等价物的净增加额", "cceAddnote");
        xjllMap.put("审计意见 (境内)", "opinionType");
        Map<String, String> zcfzMap = new HashMap<>();
        zcfzMap.put("股票代码", "securityCode");
        zcfzMap.put("股票名字", "securityNameAbbr");
        zcfzMap.put("报告时间", "reportDate");
        zcfzMap.put("报告类型", "reportType");
        zcfzMap.put("报告时间类型", "reportDateName");
        zcfzMap.put("应付账款", "accountsPayable");
        zcfzMap.put("应收账款", "accountsRece");
        zcfzMap.put("资本公积", "capitalReserve");
        zcfzMap.put("非流动资产中的在建工程", "cip");
        zcfzMap.put("合同负债", "contractLiab");
        zcfzMap.put("递延所得税资产", "deferTaxAsset");
        zcfzMap.put("应收款项融资", "financeRece");
        zcfzMap.put("非流动资产中的固定资产", "fixedAsset");
        zcfzMap.put("商誉", "goodwill");
        zcfzMap.put("持有代售资产", "holdsaleAsset");
        zcfzMap.put("持有代售负债", "holdsaleLiab");
        zcfzMap.put("无形资产", "intangibleAsset");
        zcfzMap.put("存货", "inventory");
        zcfzMap.put("租赁负债", "leaseLiab");
        zcfzMap.put("长期待摊费用", "longPrepaidExpense");
        zcfzMap.put("货币资金", "monetaryfunds");
        zcfzMap.put("应付票据及应付款帐", "noteAccountsPayable");
        zcfzMap.put("应收票据及应收款帐", "noteAccountsRece");
        zcfzMap.put("其它流动资产", "otherCurrentAsset");
        zcfzMap.put("其它流动负债", "otherCurrentLiab");
        zcfzMap.put("其它非流动资产", "otherNoncurrentAsset");
        zcfzMap.put("预计负债", "predictLiab");
        zcfzMap.put("预付款项", "prepayment");
        zcfzMap.put("实收资本（或股本）", "shareCapital");
        zcfzMap.put("应付职工薪酬", "staffSalaryPayable");
        zcfzMap.put("盈余公积", "surplusReserve");
        zcfzMap.put("应交税费", "taxPayable");
        zcfzMap.put("资产总计", "totalAssets");
        zcfzMap.put("流动资产总计", "totalCurrentAssets");
        zcfzMap.put("流动负债总计", "totalCurrentLiab");
        zcfzMap.put("股东权益合计", "totalEquity");
        zcfzMap.put("负债合计", "totalLiabilities");
        zcfzMap.put("非流动资产合计", "totalNoncurrentAssets");
        zcfzMap.put("非流动负债合计", "totalNoncurrentLiab");
        zcfzMap.put("其它应付款合计", "totalOtherPayable");
        zcfzMap.put("其它应收款合计", "totalOtherRece");
        zcfzMap.put("归属于母公司股东权益总计", "totalParentEquity");
        zcfzMap.put("未分配利润", "unassignRpofit");
        zcfzMap.put("使用权资产", "userightAsset");
        zcfzMap.put("交易性金融资产", "tradeFinassetNotfvtpl");
        zcfzMap.put("递延收益", "deferIncome");
        zcfzMap.put("负债和股东权益总计", "totalLiabEquity");
        zcfzMap.put("审计意见 (境内)", "opinionType");
        alias.put("mainzbMap", mainzbMap);
        alias.put("profileMap", profileMap);
        alias.put("xjllMap", xjllMap);
        alias.put("zcfzMap", zcfzMap);
    }

    public BaseResponse<ArrayList<GpEntity>> uploadExcel(Integer type, MultipartFile mfile) {
        if (Objects.isNull(mfile) || Objects.isNull(type)) {
            return BaseResponse.error(ErrorCode.BAD_REQUEST, "参数不全");
        }
        try {
            File file = MyUtils.transferToFile(mfile);
            ArrayList<GpEntity> gps = new ArrayList<>();
            if (type.equals(0)) {
                ExcelReader mainzbMap = ExcelUtil.getReader(file);
                mainzbMap.addHeaderAlias("股票代码", "securityCode");
                mainzbMap.addHeaderAlias("股票名字", "securityNameAbbr");
                mainzbMap.addHeaderAlias("报告时间", "reportDate");
                mainzbMap.addHeaderAlias("基本每股收益 (元)", "epsjb");
                mainzbMap.addHeaderAlias("扣非每股收益 (元)", "epskcjb");
                mainzbMap.addHeaderAlias("稀释每股收益 (元)", "epsxs");
                mainzbMap.addHeaderAlias("每股净资产 (元)", "bps");
                mainzbMap.addHeaderAlias("每股公积金 (元)", "mgzbgj");
                mainzbMap.addHeaderAlias("每股未分配利润 (元)", "mgwfplr");
                mainzbMap.addHeaderAlias("每股经营现金流 (元)", "mgjyxjje");
                mainzbMap.addHeaderAlias("营业总收入 (元)", "totaloperatereve");
                mainzbMap.addHeaderAlias("归属净利润 (元)", "parentnetprofit");
                mainzbMap.addHeaderAlias("扣非净利润 (元)", "kcfjcxsyjlr");
                mainzbMap.addHeaderAlias("营业总收入同比增长 (%)", "totaloperaterevetz");
                mainzbMap.addHeaderAlias("归属净利润同比增长 (%)", "parentnetprofittz");
                mainzbMap.addHeaderAlias("扣非净利润同比增长 (%)", "kcfjcxsyjlrtz");
                mainzbMap.addHeaderAlias("营业总收入滚动环比增长 (%)", "yyzsrgdhbzc");
                mainzbMap.addHeaderAlias("归属净利润滚动环比增长 (%)", "netprofitrphbzc");
                mainzbMap.addHeaderAlias("扣非净利润滚动环比增长 (%)", "kfjlrgdhbzc");
                mainzbMap.addHeaderAlias("净资产收益率 (加权)(%)", "roejq");
                mainzbMap.addHeaderAlias("净资产收益率 (扣非 / 加权)(%)", "roekcjq");
                mainzbMap.addHeaderAlias("总资产收益率 (加权)(%)", "zzcjll");
                mainzbMap.addHeaderAlias("毛利率 (%)", "xsmll");
                mainzbMap.addHeaderAlias("净利率 (%)", "xsjll");
                mainzbMap.addHeaderAlias("流动比率", "ld");
                mainzbMap.addHeaderAlias("速动比率", "sd");
                mainzbMap.addHeaderAlias("现金流量比率", "xjllb");
                mainzbMap.addHeaderAlias("资产负债率 (%)", "zcfzl");
                mainzbMap.addHeaderAlias("权益乘数", "qycs");
                mainzbMap.addHeaderAlias("产权比率", "cqbl");
                mainzbMap.addHeaderAlias("总资产周转天数 (天)", "zzczzts");
                mainzbMap.addHeaderAlias("存货周转天数 (天)", "chzzts");
                mainzbMap.addHeaderAlias("应收账款周转天数 (天)", "yszkzzts");
                mainzbMap.addHeaderAlias("总资产周转率 (次)", "toazzl");
                mainzbMap.addHeaderAlias("存货周转率 (次)", "chzzl");
                mainzbMap.addHeaderAlias("应收账款周转率 (次)", "yszkzzl");
                ArrayList<Mainzb> all = (ArrayList<Mainzb>) mainzbMap.readAll(Mainzb.class);
                for (Mainzb mainzb : all) {
                    gps.add(mainzb);
                }
                log.info("gps: {}", gps);
                return BaseResponse.success(gps);
            } else if (type.equals(1)) {
                ExcelReader profileMap = ExcelUtil.getReader(file);
                profileMap.addHeaderAlias("股票代码", "securityCode");
                profileMap.addHeaderAlias("股票名字", "securityNameAbbr");
                profileMap.addHeaderAlias("报告时间", "reportDate");
                profileMap.addHeaderAlias("营业总收入", "totalOperateIncome");
                profileMap.addHeaderAlias("营业收入", "operateIncome");
                profileMap.addHeaderAlias("营业总成本", "totalOperateCost");
                profileMap.addHeaderAlias("营业成本", "operateCost");
                profileMap.addHeaderAlias("税金及附加", "operateTaxAdd");
                profileMap.addHeaderAlias("销售费用", "saleExpense");
                profileMap.addHeaderAlias("管理费用", "manageExpense");
                profileMap.addHeaderAlias("研发费用", "researchExpense");
                profileMap.addHeaderAlias("财务费用", "financeExpense");
                profileMap.addHeaderAlias("其中：利息费用", "feInterestExpense");
                profileMap.addHeaderAlias("利息收入", "feInterestIncome");
                profileMap.addHeaderAlias("加：投资收益", "investIncome");
                profileMap.addHeaderAlias("资产处置收益", "assetDisposalIncome");
                profileMap.addHeaderAlias("资产减值损失 (新)", "assetImpairmentIncome");
                profileMap.addHeaderAlias("信用减值损失 (新)", "creditImpairmentIncome");
                profileMap.addHeaderAlias("其他收益", "otherIncome");
                profileMap.addHeaderAlias("营业利润", "operateProfit");
                profileMap.addHeaderAlias("加：营业外收入", "nonbusinessIncome");
                profileMap.addHeaderAlias("减：营业外支出", "nonbusinessExpense");
                profileMap.addHeaderAlias("利润总额", "totalProfit");
                profileMap.addHeaderAlias("减：所得税", "incomeTax");
                profileMap.addHeaderAlias("净利润", "netprofit");
                profileMap.addHeaderAlias("持续经营净利润", "continuedNetprofit");
                profileMap.addHeaderAlias("归属于母公司股东的净利润", "parentNetprofit");
                profileMap.addHeaderAlias("扣除非经常性损益后的净利润", "deductParentNetprofit");
                profileMap.addHeaderAlias("基本每股收益", "basicEps");
                profileMap.addHeaderAlias("稀释每股收益", "dilutedEps");
                profileMap.addHeaderAlias("综合收益总额", "totalCompreIncome");
                profileMap.addHeaderAlias("归属于母公司股东的综合收益总额", "parentTci");
                profileMap.addHeaderAlias("审计意见 (境内)", "opinionType");
                ArrayList<Profile> all = (ArrayList<Profile>) profileMap.readAll(Profile.class);
                for (Profile profile : all) {
                    gps.add(profile);
                }
                log.info("gps", gps);
                return BaseResponse.success(gps);
            } else if (type.equals(2)) {
                ExcelReader xjllMap = ExcelUtil.getReader(file);
                xjllMap.addHeaderAlias("股票代码", "securityCode");
                xjllMap.addHeaderAlias("股票名字", "securityNameAbbr");
                xjllMap.addHeaderAlias("发布日期", "reportDate");
                xjllMap.addHeaderAlias("销售商品、提供劳务收到的现金", "salesServices");
                xjllMap.addHeaderAlias("收到的税收返还", "receiveTaxRefund");
                xjllMap.addHeaderAlias("收到其他与经营活动有关的现金", "receiveOtherOperate");
                xjllMap.addHeaderAlias("经营活动现金流入小计", "totalOperateInflow");
                xjllMap.addHeaderAlias("购买商品、接受劳务支付的现金", "buyServices");
                xjllMap.addHeaderAlias("支付给职工以及为职工支付的现金", "payStaffCash");
                xjllMap.addHeaderAlias("支付的各项税费", "payAllTax");
                xjllMap.addHeaderAlias("支付其他与经营活动有关的现金", "payOtherOperate");
                xjllMap.addHeaderAlias("经营活动现金流出小计", "totalOperateOutflow");
                xjllMap.addHeaderAlias("经营活动产生的现金流量净额", "netcashOperate");
                xjllMap.addHeaderAlias("处置固定资产、无形资产和其他长期资产收回的现金净额", "disposalLongAsset");
                xjllMap.addHeaderAlias("处置子公司及其他营业单位收到的现金", "disposalSubsidiaryOther");
                xjllMap.addHeaderAlias("收到的其他与投资活动有关的现金", "receiveOtherInvest");
                xjllMap.addHeaderAlias("投资活动现金流入小计", "totalInvestInflow");
                xjllMap.addHeaderAlias("购建固定资产、无形资产和其他长期资产支付的现金", "constructLongAsset");
                xjllMap.addHeaderAlias("取得子公司及其他营业单位支付的现金净额", "obtainSubsidiaryOther");
                xjllMap.addHeaderAlias("支付其他与投资活动有关的现金", "payOtherInvest");
                xjllMap.addHeaderAlias("投资活动现金流出小计", "totalInvestOutflow");
                xjllMap.addHeaderAlias("投资活动产生的现金流量净额", "netcashInvest");
                xjllMap.addHeaderAlias("分配股利、利润或偿付利息支付的现金", "assignDividendPorfit");
                xjllMap.addHeaderAlias("筹资活动现金流出小计", "totalFinanceOutflow");
                xjllMap.addHeaderAlias("筹资活动产生的现金流量净额", "netcashFinance");
                xjllMap.addHeaderAlias("现金及现金等价物净增加额", "cceAdd");
                xjllMap.addHeaderAlias("加：期初现金及现金等价物余额", "beginCce");
                xjllMap.addHeaderAlias("期末现金及现金等价物余额", "endCce");
                xjllMap.addHeaderAlias("净利润", "netprofit");
                xjllMap.addHeaderAlias("资产减值准备", "assetImpairment");
                xjllMap.addHeaderAlias("固定资产和投资性房地产折旧", "faIrDepr");
                xjllMap.addHeaderAlias("其中：固定资产折旧、油气资产折耗、生产性生物资产折旧", "oilgasBiologyDepr");
                xjllMap.addHeaderAlias("无形资产摊销", "iaAmortize");
                xjllMap.addHeaderAlias("长期待摊费用摊销", "lpeAmortize");
                xjllMap.addHeaderAlias("处置固定资产、无形资产和其他长期资产的损失", "disposalLongassetLoss");
                xjllMap.addHeaderAlias("固定资产报废损失", "faScrapLoss");
                xjllMap.addHeaderAlias("投资损失", "investLoss");
                xjllMap.addHeaderAlias("递延所得税", "deferTax");
                xjllMap.addHeaderAlias("其中：递延所得税资产减少", "dtAssetReduce");
                xjllMap.addHeaderAlias("存货的减少", "inventoryReduce");
                xjllMap.addHeaderAlias("经营性应收项目的减少", "operateReceReduce");
                xjllMap.addHeaderAlias("经营性应付项目的增加", "operatePayableAdd");
                xjllMap.addHeaderAlias("其他", "other");
                xjllMap.addHeaderAlias("经营活动产生的现金流量净额其他项目", "operateNetcashOthernote");
//        xjllMap.addHeaderAlias("经营活动产生的现金流量净额", "netcashOperatenote");
                xjllMap.addHeaderAlias("现金的期末余额", "endCash");
                xjllMap.addHeaderAlias("减：现金的期初余额", "beginCash");
                xjllMap.addHeaderAlias("现金及现金等价物的净增加额", "cceAddnote");
                xjllMap.addHeaderAlias("审计意见 (境内)", "opinionType");
                ArrayList<Xjll> all = (ArrayList<Xjll>) xjllMap.readAll(Xjll.class);
                for (Xjll xjll : all) {
                    gps.add(xjll);
                }
                return BaseResponse.success(gps);
            } else if (type.equals(3)) {
                ExcelReader zcfzMap = ExcelUtil.getReader(file);
                zcfzMap.addHeaderAlias("股票代码", "securityCode");
                zcfzMap.addHeaderAlias("股票名字", "securityNameAbbr");
                zcfzMap.addHeaderAlias("报告时间", "reportDate");
                zcfzMap.addHeaderAlias("报告类型", "reportType");
                zcfzMap.addHeaderAlias("报告时间类型", "reportDateName");
                zcfzMap.addHeaderAlias("应付账款", "accountsPayable");
                zcfzMap.addHeaderAlias("应收账款", "accountsRece");
                zcfzMap.addHeaderAlias("资本公积", "capitalReserve");
                zcfzMap.addHeaderAlias("非流动资产中的在建工程", "cip");
                zcfzMap.addHeaderAlias("合同负债", "contractLiab");
                zcfzMap.addHeaderAlias("递延所得税资产", "deferTaxAsset");
                zcfzMap.addHeaderAlias("应收款项融资", "financeRece");
                zcfzMap.addHeaderAlias("非流动资产中的固定资产", "fixedAsset");
                zcfzMap.addHeaderAlias("商誉", "goodwill");
                zcfzMap.addHeaderAlias("持有代售资产", "holdsaleAsset");
                zcfzMap.addHeaderAlias("持有代售负债", "holdsaleLiab");
                zcfzMap.addHeaderAlias("无形资产", "intangibleAsset");
                zcfzMap.addHeaderAlias("存货", "inventory");
                zcfzMap.addHeaderAlias("租赁负债", "leaseLiab");
                zcfzMap.addHeaderAlias("长期待摊费用", "longPrepaidExpense");
                zcfzMap.addHeaderAlias("货币资金", "monetaryfunds");
                zcfzMap.addHeaderAlias("应付票据及应付款帐", "noteAccountsPayable");
                zcfzMap.addHeaderAlias("应收票据及应收款帐", "noteAccountsRece");
                zcfzMap.addHeaderAlias("其它流动资产", "otherCurrentAsset");
                zcfzMap.addHeaderAlias("其它流动负债", "otherCurrentLiab");
                zcfzMap.addHeaderAlias("其它非流动资产", "otherNoncurrentAsset");
                zcfzMap.addHeaderAlias("预计负债", "predictLiab");
                zcfzMap.addHeaderAlias("预付款项", "prepayment");
                zcfzMap.addHeaderAlias("实收资本（或股本）", "shareCapital");
                zcfzMap.addHeaderAlias("应付职工薪酬", "staffSalaryPayable");
                zcfzMap.addHeaderAlias("盈余公积", "surplusReserve");
                zcfzMap.addHeaderAlias("应交税费", "taxPayable");
                zcfzMap.addHeaderAlias("资产总计", "totalAssets");
                zcfzMap.addHeaderAlias("流动资产总计", "totalCurrentAssets");
                zcfzMap.addHeaderAlias("流动负债总计", "totalCurrentLiab");
                zcfzMap.addHeaderAlias("股东权益合计", "totalEquity");
                zcfzMap.addHeaderAlias("负债合计", "totalLiabilities");
                zcfzMap.addHeaderAlias("非流动资产合计", "totalNoncurrentAssets");
                zcfzMap.addHeaderAlias("非流动负债合计", "totalNoncurrentLiab");
                zcfzMap.addHeaderAlias("其它应付款合计", "totalOtherPayable");
                zcfzMap.addHeaderAlias("其它应收款合计", "totalOtherRece");
                zcfzMap.addHeaderAlias("归属于母公司股东权益总计", "totalParentEquity");
                zcfzMap.addHeaderAlias("未分配利润", "unassignRpofit");
                zcfzMap.addHeaderAlias("使用权资产", "userightAsset");
                zcfzMap.addHeaderAlias("交易性金融资产", "tradeFinassetNotfvtpl");
                zcfzMap.addHeaderAlias("递延收益", "deferIncome");
                zcfzMap.addHeaderAlias("负债和股东权益总计", "totalLiabEquity");
                zcfzMap.addHeaderAlias("审计意见 (境内)", "opinionType");
                ArrayList<Zcfz> all = (ArrayList<Zcfz>) zcfzMap.readAll(Zcfz.class);
                for (Zcfz zcfz : all) {
                    gps.add(zcfz);
                }
                return BaseResponse.success(gps);
            } else if (type == 4) {
                ExcelReader companyInfoMap = ExcelUtil.getReader(file);
                companyInfoMap.addHeaderAlias("公司名称", "gsmc");
                companyInfoMap.addHeaderAlias("英文名称", "ywmc");
                companyInfoMap.addHeaderAlias("曾用名", "cym");
                companyInfoMap.addHeaderAlias("A股代码", "agdm");
                companyInfoMap.addHeaderAlias("A股简称", "agjc");
                companyInfoMap.addHeaderAlias("B股代码", "bgdm");
                companyInfoMap.addHeaderAlias("B股简称", "bgjc");
                companyInfoMap.addHeaderAlias("H股代码", "hgdm");
                companyInfoMap.addHeaderAlias("H股简称", "hgjc");
                companyInfoMap.addHeaderAlias("证券类别", "zqlb");
                companyInfoMap.addHeaderAlias("所属东财行业", "sshy");
                companyInfoMap.addHeaderAlias("上市交易所", "ssjys");
                companyInfoMap.addHeaderAlias("所属证监会行业", "sszjhhy");
                companyInfoMap.addHeaderAlias("总经理", "zjl");
                companyInfoMap.addHeaderAlias("法人代表", "frdb");
                companyInfoMap.addHeaderAlias("董秘", "dm");
                companyInfoMap.addHeaderAlias("董事长", "dsz");
                companyInfoMap.addHeaderAlias("电子邮箱", "dzxx");
                companyInfoMap.addHeaderAlias("传真", "cz");
                companyInfoMap.addHeaderAlias("联系电话", "lxdh");
                companyInfoMap.addHeaderAlias("公司网址", "gswz");
                companyInfoMap.addHeaderAlias("办公地址", "bgdz");
                companyInfoMap.addHeaderAlias("注册地址", "zcdz");
                companyInfoMap.addHeaderAlias("区域", "qy");
                companyInfoMap.addHeaderAlias("邮政编码", "yzbm");
                companyInfoMap.addHeaderAlias("注册资本 (元)", "zczb");
                companyInfoMap.addHeaderAlias("工商登记", "gsdj");
                companyInfoMap.addHeaderAlias("公司简介", "gsjj");
                companyInfoMap.addHeaderAlias("经营范围", "jyfw");
                companyInfoMap.addHeaderAlias("注册地", "zcd");
                companyInfoMap.addHeaderAlias("公司秘书", "gsms");
                companyInfoMap.addHeaderAlias("年结日", "njr");
                companyInfoMap.addHeaderAlias("员工人数", "ygrs");
                companyInfoMap.addHeaderAlias("成立日期", "clrq");
                companyInfoMap.addHeaderAlias("上市日期", "ssrq");
                companyInfoMap.addHeaderAlias("核数师", "hss");
                ArrayList<CompanyInfo> all = (ArrayList<CompanyInfo>) companyInfoMap.readAll(CompanyInfo.class);
                for (CompanyInfo companyInfo : all) {
                    gps.add(companyInfo);
                }
                return BaseResponse.success(gps);
            } else if (type == 5) {
                ExcelReader qygqjgMap = ExcelUtil.getReader(file);
                qygqjgMap.addHeaderAlias("股票代码", "securityCode");
                qygqjgMap.addHeaderAlias("股东名称", "holderName");
                qygqjgMap.addHeaderAlias("股东性质", "holderType");
                qygqjgMap.addHeaderAlias("股份类型", "sharesType");
                qygqjgMap.addHeaderAlias("持股数 (股)", "holdNum");
                qygqjgMap.addHeaderAlias("占总流通股本持股比例", "freeHoldnumRatio");
                qygqjgMap.addHeaderAlias("增减 (股)", "holdNumChange");
                qygqjgMap.addHeaderAlias("变动比例", "changeRatio");
                ArrayList<Qygqjg> all = (ArrayList<Qygqjg>) qygqjgMap.readAll(Qygqjg.class);
                for (Qygqjg qygqjg : all) {
                    gps.add(qygqjg);
                }
                return BaseResponse.success(gps);
            } else {
                return BaseResponse.error(ErrorCode.FILE_ERROR, "文件格式错误，建议在模版文件中修改");
            }
        } catch (Exception e) {
            return BaseResponse.error(ErrorCode.FILE_ERROR, "文件格式错误，建议在模版文件中修改");
        }
    }

    public void downloadExcel(Integer type, HttpServletResponse response, String gpName) {
        if (type == 0) {
            List<Mainzb> mainzbs = gpDao.getMainzbList(gpName).subList(0, 1);
            ExcelWriter writer = ExcelUtil.getWriter(true);
            writer.addHeaderAlias("securityCode", "股票代码");
            writer.addHeaderAlias("securityNameAbbr", "股票名字");
            writer.addHeaderAlias("reportDate", "报告时间");
            writer.addHeaderAlias("epsjb", "基本每股收益 (元)");
            writer.addHeaderAlias("epskcjb", "扣非每股收益 (元)");
            writer.addHeaderAlias("epsxs", "稀释每股收益 (元)");
            writer.addHeaderAlias("bps", "每股净资产 (元)");
            writer.addHeaderAlias("mgzbgj", "每股公积金 (元)");
            writer.addHeaderAlias("mgwfplr", "每股未分配利润 (元)");
            writer.addHeaderAlias("mgjyxjje", "每股经营现金流 (元)");
            writer.addHeaderAlias("totaloperatereve", "营业总收入 (元)");
            writer.addHeaderAlias("parentnetprofit", "归属净利润 (元)");
            writer.addHeaderAlias("kcfjcxsyjlr", "扣非净利润 (元)");
            writer.addHeaderAlias("totaloperaterevetz", "营业总收入同比增长 (%)");
            writer.addHeaderAlias("parentnetprofittz", "归属净利润同比增长 (%)");
            writer.addHeaderAlias("kcfjcxsyjlrtz", "扣非净利润同比增长 (%)");
            writer.addHeaderAlias("yyzsrgdhbzc", "营业总收入滚动环比增长 (%)");
            writer.addHeaderAlias("netprofitrphbzc", "归属净利润滚动环比增长 (%)");
            writer.addHeaderAlias("kfjlrgdhbzc", "扣非净利润滚动环比增长 (%)");
            writer.addHeaderAlias("roejq", "净资产收益率 (加权)(%)");
            writer.addHeaderAlias("roekcjq", "净资产收益率 (扣非 / 加权)(%)");
            writer.addHeaderAlias("zzcjll", "总资产收益率 (加权)(%)");
            writer.addHeaderAlias("xsmll", "毛利率 (%)");
            writer.addHeaderAlias("xsjll", "净利率 (%)");
            writer.addHeaderAlias("ld", "流动比率");
            writer.addHeaderAlias("sd", "速动比率");
            writer.addHeaderAlias("xjllb", "现金流量比率");
            writer.addHeaderAlias("zcfzl", "资产负债率 (%)");
            writer.addHeaderAlias("qycs", "权益乘数");
            writer.addHeaderAlias("cqbl", "产权比率");
            writer.addHeaderAlias("zzczzts", "总资产周转天数 (天)");
            writer.addHeaderAlias("chzzts", "存货周转天数 (天)");
            writer.addHeaderAlias("yszkzzts", "应收账款周转天数 (天)");
            writer.addHeaderAlias("toazzl", "总资产周转率 (次)");
            writer.addHeaderAlias("chzzl", "存货周转率 (次)");
            writer.addHeaderAlias("yszkzzl", "应收账款周转率 (次)");
            for (int i = 0; i < 100; ++i) {
                writer.setColumnWidth(i, 20);
            }
            writer.write(mainzbs, true);
            try {
                // 获取我们的输出流
                final OutputStream output = response.getOutputStream();
                response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("主要指标模版.xlsx", "UTF-8"));
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                writer.flush(output, true);
                writer.close();
                // 这里可以自行关闭资源或者写一个关闭资源的工具类
                IoUtil.close(output);
            } catch (IOException e) {
                log.error("EducationServiceImpl [export] 输出到响应流失败", e);
                throw new ApiException("导出Excel异常");
            }
            return;
        }
        if (type == 1) {
            List<Profile> profileList = gpDao.getProfileList(gpName);
            ExcelWriter writer = ExcelUtil.getWriter(true);
            writer.addHeaderAlias("securityCode", "股票代码");
            writer.addHeaderAlias("securityNameAbbr", "股票名字");
            writer.addHeaderAlias("reportDate", "报告时间");
            writer.addHeaderAlias("totalOperateIncome", "营业总收入");
            writer.addHeaderAlias("operateIncome", "营业收入");
            writer.addHeaderAlias("totalOperateCost", "营业总成本");
            writer.addHeaderAlias("operateCost", "营业成本");
            writer.addHeaderAlias("operateTaxAdd", "税金及附加");
            writer.addHeaderAlias("saleExpense", "销售费用");
            writer.addHeaderAlias("manageExpense", "管理费用");
            writer.addHeaderAlias("researchExpense", "研发费用");
            writer.addHeaderAlias("financeExpense", "财务费用");
            writer.addHeaderAlias("feInterestExpense", "其中：利息费用");
            writer.addHeaderAlias("feInterestIncome", "利息收入");
            writer.addHeaderAlias("investIncome", "加：投资收益");
            writer.addHeaderAlias("assetDisposalIncome", "资产处置收益");
            writer.addHeaderAlias("assetImpairmentIncome", "资产减值损失 (新)");
            writer.addHeaderAlias("creditImpairmentIncome", "信用减值损失 (新)");
            writer.addHeaderAlias("otherIncome", "其他收益");
            writer.addHeaderAlias("operateProfit", "营业利润");
            writer.addHeaderAlias("nonbusinessIncome", "加：营业外收入");
            writer.addHeaderAlias("nonbusinessExpense", "减：营业外支出");
            writer.addHeaderAlias("totalProfit", "利润总额");
            writer.addHeaderAlias("incomeTax", "减：所得税");
            writer.addHeaderAlias("netprofit", "净利润");
            writer.addHeaderAlias("continuedNetprofit", "持续经营净利润");
            writer.addHeaderAlias("parentNetprofit", "归属于母公司股东的净利润");
            writer.addHeaderAlias("deductParentNetprofit", "扣除非经常性损益后的净利润");
            writer.addHeaderAlias("basicEps", "基本每股收益");
            writer.addHeaderAlias("dilutedEps", "稀释每股收益");
            writer.addHeaderAlias("totalCompreIncome", "综合收益总额");
            writer.addHeaderAlias("parentTci", "归属于母公司股东的综合收益总额");
            writer.addHeaderAlias("opinionType", "审计意见 (境内)");
            for (int i = 0; i < 100; ++i) {
                writer.setColumnWidth(i, 20);
            }
            writer.write(profileList, true);
            try {
                // 获取我们的输出流
                final OutputStream output = response.getOutputStream();
                response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("利润表模版.xlsx", "UTF-8"));
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                writer.flush(output, true);
                writer.close();
                // 这里可以自行关闭资源或者写一个关闭资源的工具类
                IoUtil.close(output);
            } catch (IOException e) {
                log.error("EducationServiceImpl [export] 输出到响应流失败", e);
                throw new ApiException("导出Excel异常");
            }
            return;
        }
        if (type == 2) {
            List<Xjll> xjlls = gpDao.getXjllList(gpName).subList(0, 1);
            ExcelWriter writer = ExcelUtil.getWriter(true);
            writer.addHeaderAlias("securityCode", "股票代码");
            writer.addHeaderAlias("securityNameAbbr", "股票名字");
            writer.addHeaderAlias("reportDate", "发布日期");
            writer.addHeaderAlias("salesServices", "销售商品、提供劳务收到的现金");
            writer.addHeaderAlias("receiveTaxRefund", "收到的税收返还");
            writer.addHeaderAlias("receiveOtherOperate", "收到其他与经营活动有关的现金");
            writer.addHeaderAlias("totalOperateInflow", "经营活动现金流入小计");
            writer.addHeaderAlias("buyServices", "购买商品、接受劳务支付的现金");
            writer.addHeaderAlias("payStaffCash", "支付给职工以及为职工支付的现金");
            writer.addHeaderAlias("payAllTax", "支付的各项税费");
            writer.addHeaderAlias("payOtherOperate", "支付其他与经营活动有关的现金");
            writer.addHeaderAlias("totalOperateOutflow", "经营活动现金流出小计");
            writer.addHeaderAlias("netcashOperate", "经营活动产生的现金流量净额");
            writer.addHeaderAlias("disposalLongAsset", "处置固定资产、无形资产和其他长期资产收回的现金净额");
            writer.addHeaderAlias("disposalSubsidiaryOther", "处置子公司及其他营业单位收到的现金");
            writer.addHeaderAlias("receiveOtherInvest", "收到的其他与投资活动有关的现金");
            writer.addHeaderAlias("totalInvestInflow", "投资活动现金流入小计");
            writer.addHeaderAlias("constructLongAsset", "购建固定资产、无形资产和其他长期资产支付的现金");
            writer.addHeaderAlias("obtainSubsidiaryOther", "取得子公司及其他营业单位支付的现金净额");
            writer.addHeaderAlias("payOtherInvest", "支付其他与投资活动有关的现金");
            writer.addHeaderAlias("totalInvestOutflow", "投资活动现金流出小计");
            writer.addHeaderAlias("netcashInvest", "投资活动产生的现金流量净额");
            writer.addHeaderAlias("assignDividendPorfit", "分配股利、利润或偿付利息支付的现金");
            writer.addHeaderAlias("totalFinanceOutflow", "筹资活动现金流出小计");
            writer.addHeaderAlias("netcashFinance", "筹资活动产生的现金流量净额");
            writer.addHeaderAlias("cceAdd", "现金及现金等价物净增加额");
            writer.addHeaderAlias("beginCce", "加：期初现金及现金等价物余额");
            writer.addHeaderAlias("endCce", "期末现金及现金等价物余额");
            writer.addHeaderAlias("netprofit", "净利润");
            writer.addHeaderAlias("assetImpairment", "资产减值准备");
            writer.addHeaderAlias("faIrDepr", "固定资产和投资性房地产折旧");
            writer.addHeaderAlias("oilgasBiologyDepr", "其中：固定资产折旧、油气资产折耗、生产性生物资产折旧");
            writer.addHeaderAlias("iaAmortize", "无形资产摊销");
            writer.addHeaderAlias("lpeAmortize", "长期待摊费用摊销");
            writer.addHeaderAlias("disposalLongassetLoss", "处置固定资产、无形资产和其他长期资产的损失");
            writer.addHeaderAlias("faScrapLoss", "固定资产报废损失");
            writer.addHeaderAlias("investLoss", "投资损失");
            writer.addHeaderAlias("deferTax", "递延所得税");
            writer.addHeaderAlias("dtAssetReduce", "其中：递延所得税资产减少");
            writer.addHeaderAlias("inventoryReduce", "存货的减少");
            writer.addHeaderAlias("operateReceReduce", "经营性应收项目的减少");
            writer.addHeaderAlias("operatePayableAdd", "经营性应付项目的增加");
            writer.addHeaderAlias("other", "其他");
            writer.addHeaderAlias("operateNetcashOthernote", "经营活动产生的现金流量净额其他项目");
            writer.addHeaderAlias("netcashOperatenote", "经营活动产生的现金流量净额");
            writer.addHeaderAlias("endCash", "现金的期末余额");
            writer.addHeaderAlias("beginCash", "减：现金的期初余额");
            writer.addHeaderAlias("cceAddnote", "现金及现金等价物的净增加额");
            writer.addHeaderAlias("opinionType", "审计意见 (境内)");
            for (int i = 0; i < 100; ++i) {
                writer.setColumnWidth(i, 20);
            }
            writer.write(xjlls, true);
            try {
                // 获取我们的输出流
                final OutputStream output = response.getOutputStream();
                response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("现金流量表模版.xlsx", "UTF-8"));
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                writer.flush(output, true);
                writer.close();
                // 这里可以自行关闭资源或者写一个关闭资源的工具类
                IoUtil.close(output);
            } catch (IOException e) {
                log.error("EducationServiceImpl [export] 输出到响应流失败", e);
                throw new ApiException("导出Excel异常");
            }
        }
        if (type == 3) {
            List<Zcfz> zcfzs = gpDao.getZcfzList(gpName);
            ExcelWriter writer = ExcelUtil.getWriter(true);
            writer.addHeaderAlias("securityCode", "股票代码");
            writer.addHeaderAlias("securityNameAbbr", "股票名字");
            writer.addHeaderAlias("reportDate", "报告时间");
            writer.addHeaderAlias("reportType", "报告类型");
            writer.addHeaderAlias("reportDateName", "报告时间类型");
            writer.addHeaderAlias("accountsPayable", "应收账款");
            writer.addHeaderAlias("accountsRece", "应收账款");
            writer.addHeaderAlias("capitalReserve", "资本公积");
            writer.addHeaderAlias("cip", "非流动资产中的在建工程");
            writer.addHeaderAlias("contractLiab", "合同负债");
            writer.addHeaderAlias("deferTaxAsset", "递延所得税资产");
            writer.addHeaderAlias("financeRece", "应收款项融资");
            writer.addHeaderAlias("fixedAsset", "非流动资产中的固定资产");
            writer.addHeaderAlias("goodwill", "商誉");
            writer.addHeaderAlias("holdsaleAsset", "持有代售资产");
            writer.addHeaderAlias("holdsaleLiab", "持有代售负债");
            writer.addHeaderAlias("intangibleAsset", "无形资产");
            writer.addHeaderAlias("inventory", "存货");
            writer.addHeaderAlias("leaseLiab", "租赁负债");
            writer.addHeaderAlias("longPrepaidExpense", "长期待摊费用");
            writer.addHeaderAlias("monetaryfunds", "货币资金");
            writer.addHeaderAlias("noteAccountsPayable", "应付票据及应付款帐");
            writer.addHeaderAlias("noteAccountsRece", "应收票据及应收款帐");
            writer.addHeaderAlias("otherCurrentAsset", "其它流动资产");
            writer.addHeaderAlias("otherCurrentLiab", "其它流动负债");
            writer.addHeaderAlias("otherNoncurrentAsset", "其它非流动资产");
            writer.addHeaderAlias("predictLiab", "预计负债");
            writer.addHeaderAlias("prepayment", "预付款项");
            writer.addHeaderAlias("shareCapital", "实收资本（或股本）");
            writer.addHeaderAlias("staffSalaryPayable", "应付职工薪酬");
            writer.addHeaderAlias("surplusReserve", "盈余公积");
            writer.addHeaderAlias("taxPayable", "应交税费");
            writer.addHeaderAlias("totalAssets", "资产总计");
            writer.addHeaderAlias("totalCurrentAssets", "流动资产总计");
            writer.addHeaderAlias("totalCurrentLiab", "流动负债总计");
            writer.addHeaderAlias("totalEquity", "股东权益合计");
            writer.addHeaderAlias("totalLiabilities", "负债合计");
            writer.addHeaderAlias("totalNoncurrentAssets", "非流动资产合计");
            writer.addHeaderAlias("totalNoncurrentLiab", "非流动负债合计");
            writer.addHeaderAlias("totalOtherPayable", "其它应付款合计");
            writer.addHeaderAlias("totalOtherRece", "其它应收款合计");
            writer.addHeaderAlias("totalParentEquity", "归属于母公司股东权益总计");
            writer.addHeaderAlias("unassignRpofit", "未分配利润");
            writer.addHeaderAlias("userightAsset", "使用权资产");
            writer.addHeaderAlias("tradeFinassetNotfvtpl", "交易性金融资产");
            writer.addHeaderAlias("deferIncome", "递延收益");
            writer.addHeaderAlias("totalLiabEquity", "负债和股东权益总计");
            writer.addHeaderAlias("opinionType", "审计意见 (境内)");
            for (int i = 0; i < 100; ++i) {
                writer.setColumnWidth(i, 20);
            }
            writer.write(zcfzs, true);
            try {
                // 获取我们的输出流
                final OutputStream output = response.getOutputStream();
                response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("资产负债表模版.xlsx", "UTF-8"));
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                writer.flush(output, true);
                writer.close();
                // 这里可以自行关闭资源或者写一个关闭资源的工具类
                IoUtil.close(output);
            } catch (IOException e) {
                log.error("EducationServiceImpl [export] 输出到响应流失败", e);
                throw new ApiException("导出Excel异常");
            }
        }
        if (type == 4) {
            List<CompanyInfo> companyInfo = Collections.singletonList(gpDao.getCompanyInfoList(gpName));
            ExcelWriter writer = ExcelUtil.getWriter(true);
            writer.addHeaderAlias("gsmc", "公司名称");
            writer.addHeaderAlias("ywmc", "英文名称");
            writer.addHeaderAlias("cym", "曾用名");
            writer.addHeaderAlias("agdm", "A股代码");
            writer.addHeaderAlias("agjc", "A股简称");
            writer.addHeaderAlias("bgdm", "B股代码");
            writer.addHeaderAlias("bgjc", "B股简称");
            writer.addHeaderAlias("hgdm", "H股代码");
            writer.addHeaderAlias("hgjc", "H股简称");
            writer.addHeaderAlias("zqlb", "证券类别");
            writer.addHeaderAlias("sshy", "所属东财行业");
            writer.addHeaderAlias("ssjys", "上市交易所");
            writer.addHeaderAlias("sszjhhy", "所属证监会行业");
            writer.addHeaderAlias("zjl", "总经理");
            writer.addHeaderAlias("frdb", "法人代表");
            writer.addHeaderAlias("dm", "董秘");
            writer.addHeaderAlias("dsz", "董事长");
            writer.addHeaderAlias("dzxx", "电子邮箱");
            writer.addHeaderAlias("cz", "传真");
            writer.addHeaderAlias("lxdh", "联系电话");
            writer.addHeaderAlias("gswz", "公司网址");
            writer.addHeaderAlias("bgdz", "办公地址");
            writer.addHeaderAlias("zcdz", "注册地址");
            writer.addHeaderAlias("qy", "区域");
            writer.addHeaderAlias("yzbm", "邮政编码");
            writer.addHeaderAlias("zczb", "注册资本 (元)");
            writer.addHeaderAlias("gsdj", "工商登记");
            writer.addHeaderAlias("gsjj", "公司简介");
            writer.addHeaderAlias("jyfw", "经营范围");
            writer.addHeaderAlias("zcd", "注册地");
            writer.addHeaderAlias("gsms", "公司秘书");
            writer.addHeaderAlias("njr", "年结日");
            writer.addHeaderAlias("ygrs", "员工人数");
            writer.addHeaderAlias("clrq", "成立日期");
            writer.addHeaderAlias("ssrq", "上市日期");
            writer.addHeaderAlias("hss", "核数师");
            for (int i = 0; i < 100; ++i) {
                writer.setColumnWidth(i, 20);
            }
            writer.write(companyInfo, true);
            try {
                // 获取我们的输出流
                final OutputStream output = response.getOutputStream();
                response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("企业基本信息模版.xlsx", "UTF-8"));
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                writer.flush(output, true);
                writer.close();
                // 这里可以自行关闭资源或者写一个关闭资源的工具类
                IoUtil.close(output);
            } catch (IOException e) {
                log.error("EducationServiceImpl [export] 输出到响应流失败", e);
                throw new ApiException("导出Excel异常");
            }
        }
        if (type == 5) {
            CompanyInfo companyInfo = gpDao.getCompanyInfoList(gpName);
            List<Qygqjg> qygqjgs = gpDao.getQygqjgList(companyInfo.getAgdm());
            ExcelWriter writer = ExcelUtil.getWriter(true);
            writer.addHeaderAlias("securityCode", "股票代码");
            writer.addHeaderAlias("holderName", "股东名称");
            writer.addHeaderAlias("holderType", "股东性质");
            writer.addHeaderAlias("sharesType", "股份类型");
            writer.addHeaderAlias("holdNum", "持股数 (股)");
            writer.addHeaderAlias("freeHoldnumRatio", "占总流通股本持股比例");
            writer.addHeaderAlias("holdNumChange", "增减 (股)");
            writer.addHeaderAlias("changeRatio", "变动比例");
            for (int i = 0; i < 100; ++i) {
                writer.setColumnWidth(i, 20);
            }
            writer.write(qygqjgs, true);
            try {
                // 获取我们的输出流
                final OutputStream output = response.getOutputStream();
                response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("企业股权结构模版.xlsx", "UTF-8"));
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                writer.flush(output, true);
                writer.close();
                // 这里可以自行关闭资源或者写一个关闭资源的工具类
                IoUtil.close(output);
            } catch (IOException e) {
                log.error("EducationServiceImpl [export] 输出到响应流失败", e);
                throw new ApiException("导出Excel异常");
            }
        }
    }
}
